package accountsEx;

import javax.faces.component.UIInput;
import javax.faces.event.ActionEvent;

public class AccountSearcher {

    private Account account;

    private UIInput accountTextField;
    private UIInput bankNameTextField;
    private UIInput customerNameTextField;
    private UIInput branchNameTextField;
    private UIInput openDateTextField;
    private UIInput closingBalanceTextField;
    private UIInput addressTextArea;
    private UIInput emailIdTextField;
    private UIInput phoneNumberTextField;
    

    public AccountSearcher() {
        AccountCreator.createTestAccounts();
    }

    public void search(ActionEvent actionEvent){

        String strAccountNo = (String)getAccountTextField().getSubmittedValue();
        long accountNo = 0L;
        try{
            accountNo = Long.parseLong(strAccountNo);
            account = AccountCreator.getAccountInfo(accountNo);
            if (account != null){
                setComponentsValueToNull();
            }else{
                // Error Message.
            }
        }catch(Exception exception){
            exception.printStackTrace();
        }
    }

    private void setComponentsValueToNull(){
        bankNameTextField.setSubmittedValue(null);
        customerNameTextField.setSubmittedValue(null);
        branchNameTextField.setSubmittedValue(null);
        openDateTextField.setSubmittedValue(null);
        closingBalanceTextField.setSubmittedValue(null);
        addressTextArea.setSubmittedValue(null);
        emailIdTextField.setSubmittedValue(null);
        phoneNumberTextField.setSubmittedValue(null);
    }    

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public UIInput getAccountTextField() {
        return accountTextField;
    }

    public void setAccountTextField(UIInput accountTextField) {
        this.accountTextField = accountTextField;
    }

    public UIInput getBankNameTextField() {
        return bankNameTextField;
    }

    public void setBankNameTextField(UIInput bankNameTextField) {
        this.bankNameTextField = bankNameTextField;
    }

    public UIInput getCustomerNameTextField() {
        return customerNameTextField;
    }
 
    public void setCustomerNameTextField(UIInput customerNameTextField) {
        this.customerNameTextField = customerNameTextField;
    }

    public UIInput getBranchNameTextField() {
        return branchNameTextField;
    }

    public void setBranchNameTextField(UIInput branchNameTextField) {
        this.branchNameTextField = branchNameTextField;
    }

    public UIInput getOpenDateTextField() {
        return openDateTextField;
    }

    public void setOpenDateTextField(UIInput openDateTextField) {
        this.openDateTextField = openDateTextField;
    }

    public UIInput getClosingBalanceTextField() {
        return closingBalanceTextField;
    }

    public void setClosingBalanceTextField(UIInput closingBalanceTextField) {
        this.closingBalanceTextField = closingBalanceTextField;
    }

    public UIInput getAddressTextArea() {
        return addressTextArea;
    }

    public void setAddressTextArea(UIInput addressTextArea) {
        this.addressTextArea = addressTextArea;
    }

    public UIInput getEmailIdTextField() {
        return emailIdTextField;
    }

    public void setEmailIdTextField(UIInput emailIdTextField) {
        this.emailIdTextField = emailIdTextField;
    }

    public UIInput getPhoneNumberTextField() {
        return phoneNumberTextField;
    }

    public void setPhoneNumberTextField(UIInput phoneNumberTextField) {
        this.phoneNumberTextField = phoneNumberTextField;
    }
}
